/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.agh.air.bpel2bpmn.comparator.impl;

import org.agh.air.bpel2bpmn.comparator.AbstractComparator;
import org.agh.air.bpel2bpmn.exception.PatternNotFoundException;
import org.w3c.dom.Node;

/**
 *
 * @author paletz
 */
public class MultipleMergeComparator extends AbstractComparator {

    /* <sequence>
    <flow name="Gateway-13270">
    <invoke name="Task-13273" partnerLink="" portType="" operation="" inputVariable="" outputVariable=""/>
    
    <invoke name="Task-13276" partnerLink="" portType="" operation="" inputVariable="" outputVariable=""/>
    
    </flow>
    <invoke name="Task-13279" partnerLink="" portType="" operation="" inputVariable="" outputVariable=""/>
    
    </sequence>
     */
    @Override
    public String compare(Node node) throws PatternNotFoundException {
        if (node.getNodeName().equals(SEQUENCE)) {
            if (node.hasChildNodes() && node.getChildNodes().getLength() == 2) {
                if (getFirstChild(node).getNodeName().startsWith("parallel_split")) {
                    if (getSecondChild(node).getNodeName().equals(INVOKE)) {
                        return "multiple_merge"+ LTMP + getFirstChild(node).getNodeName().replaceFirst("parallel_split", "") + "." + getNameAttribute(getSecondChild(node)) + RTMP;
                    } else {
                        return "multiple_merge"+ LTMP + getFirstChild(node).getNodeName().replaceFirst("parallel_split", "") + "." + getSecondChild(node).getNodeName() + RTMP;
                    }
                }
            }
        }


        throw new PatternNotFoundException();
    }
}
